package com.axjy.web;

import com.axjy.service.PermissionService;
import com.axjy.util.Log;
import com.axjy.web.vo.Node;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by zjn on 2018/2/3.
 */
@RestController
@RequestMapping("/permission/permission")
public class PermissionHandler {

    @Resource
    private PermissionService permissionService;

    @GetMapping("/tree")

    public List<Node> search4Tree(Integer roleId){
        return permissionService.search4Tree(roleId);
    }

    @PostMapping("/grant")
    public String grant(Integer roleId,Integer[] mids){
        String msg=null;
        try{
            permissionService.grant4Role(roleId,mids);
            msg="角色授权成功";
        }catch (RuntimeException ex){
            msg="角色授权失败";
            Log.logger.error(ex);
        }
        return msg;
    }

}
